package lesson2.api.helpers;

import lesson2.api.ApplicationManager;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public class WebElementHelper
{
	private final ApplicationManager app;

	public WebElementHelper(ApplicationManager p_app)
	{
		app = p_app;
	}

	public void click(By p_locator)
	{
		app.driver.findElement(p_locator).click();
	}

	public void type(By p_locator, String p_text)
	{
		app.driver.findElement(p_locator).clear();
		app.driver.findElement(p_locator).sendKeys(p_text);
	}

	public void selectByValue(By p_locator, String p_value)
	{
		WebElement selectLanguage = app.driver.findElement(p_locator);
		Select select = new Select(selectLanguage);
		select.selectByValue(p_value);
	}

	public boolean isElementPresent(By p_locator)
	{
		try
		{
			app.driver.findElement(p_locator);
			return true;
		}
		catch (NoSuchElementException ex)
		{
			return false;
		}

	}

}
